export default {
	data() {
		return {
			// 接口地址
			apiUrl: '',
			// get请求参数
			params: {},
			//存放列表数据
			list: [],
			// 状态：用于判断有没有更多页
			status: 'more',
			// 用于判断是否是拉下刷新
			reload: false,
			// 当前页
			pageNum: 1,
			// 每页条数
			pageSize: 10,
			commentCount: '',
			favorableRate: ''
		};
	},
	// 下拉刷新
	onPullDownRefresh() {
		this.searchValue = ''
		this.pageNum = 1;
		this.reload = true;
		this.miXinInit();
	},
	// 上拉加载
	onReachBottom() {
		if (this.status === 'loadmore') {
			this.pageNum = this.pageNum + 1;
			this.miXinInit()
		}
	},
	methods: {
		// 重置参数
		toReset() {
			this.list = [];
			this.status = 'loadmore';
			this.reload = false;
			this.pageNum = 1;
			this.pageSize = 10;
		},
		miXinInit() {
			// 需要在beforeInit方法里面写url、params、baseURL等的赋值
			this.beforeInit();
			this.status = 'loading';
			this.$u.get(this.apiUrl, this.params).then(res => {
				console.log(data instanceof Array, 'minxi列表', res)
				let {
					data,
					count,

				} = res
				if (data instanceof Array == false) {
					let {
						goodsComments,
						commentCount,
						favorableRate
					} = data
					if (goodsComments) {
						count = goodsComments.count
						data = goodsComments.data
						this.commentCount = commentCount
						this.favorableRate = favorableRate
					}
				}

				// 如果是下拉刷新
				if (this.reload) {
					this.list = data;
					uni.stopPullDownRefresh();
					this.reload = false;
				} else {
					this.list = this.list.concat(data);
				}
				// 如果条数小于10条，表示没有更多

				if (this.list.length == count) {
					this.status = 'nomore';
				} else {
					this.status = 'loadmore';
				}
				console.log(data instanceof Array, 'minxi列表', this.list)
			});
		}
	}
};
